package com.skytech.ibe.hotel.mw.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.beanutils.BeanUtils;

import com.skytech.ibe.hotel.model.HotelBooking;
import com.skytech.ibe.hotel.model.HotelDetails;
import com.skytech.ibe.hotel.model.HotelDetailsResponse;
import com.skytech.ibe.hotel.model.HotelInfo;
import com.skytech.ibe.hotel.model.HotelInfoResponse;

public class Converter {
	public Map<String, String> convert2Map(HotelInfo hotelInfo) {
		Map<String, String> map = new HashMap<String, String>();
		map.put("name", hotelInfo.getName());
		map.put("id", hotelInfo.getId());
		map.put("address", hotelInfo.getAddress());
		map.put("room_price", String.valueOf(hotelInfo.getRoomPrice()));
		return map;
	} 
	
	
	
	
	
	public HotelInfoResponse convert2HotelInfoResponse(ArrayList<Map<String, String>> hotelMapList) throws Exception {
		HotelInfoResponse res = new HotelInfoResponse();
		ArrayList<HotelInfo> h = new ArrayList<HotelInfo>();
		for (Map<String, String> hotelMap : hotelMapList) {
			h.add(convert2HotelInfo(hotelMap));
		}
		res.setHotelInfoList(h);
		return res;
	}

	public HotelDetailsResponse convert2HotelInfoJoinResponse(ArrayList<Map<String, String>> hotelMapList) throws Exception {
		HotelDetailsResponse res = new HotelDetailsResponse();
		System.out.println("hotelMapList::" + hotelMapList.size());
		ArrayList<HotelDetails> h = new ArrayList<HotelDetails>();
		for (Map<String, String> hotelMap : hotelMapList) {
			h.add(convert2HotelDetailsBooking(hotelMap));
		}
		res.setHotelDetailsList(h);
		return res;
	}
	
	private HotelInfo convert2HotelInfo(Map<String, String> hotelMap) throws Exception {
		HotelInfo h = new HotelInfo();
		BeanUtils.populate(h, hotelMap);
		return h;
	}
	
	private HotelDetails convert2HotelDetailsBooking(Map<String, String> hotelMap) throws Exception {
		HotelDetails ht = new HotelDetails();
		HotelInfo hts = new HotelInfo();
		HotelBooking htb = new HotelBooking();
		System.out.println("hotelMap:" + hotelMap.size());
		BeanUtils.populate(hts, hotelMap);
		BeanUtils.populate(htb, hotelMap);
		ht.setHotelInfo(hts);
		ht.setHotelBooking(htb);
		return ht;
	}
	
	
	public Map<String, String> convert2Map(HotelBooking hotelBooking) {
		Map<String, String> map = new HashMap<String, String>();
		map.put("id", hotelBooking.getId());
		map.put("hotel_id", hotelBooking.getHotelId());
		map.put("room_count", String.valueOf(hotelBooking.getRoomCount()));
		map.put("price", String.valueOf(hotelBooking.getPrice()));
		map.put("from_dt", "2014-04-12");
		map.put("to_dt", "2014-04-14");
		return map;
	}
	
	public HotelBooking convert2HotelBooking(Map<String, String> hotelMap) throws Exception {
		HotelBooking h = new HotelBooking();
		BeanUtils.populate(h, hotelMap);
		return h;
	}
}
